home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program performs a horizontal smoothing, with one row of the matrix
- * per processor. The matrix is of size M x N. Each iteration of the
- * algorithm sets row i to be the average of rows i-1 and i+1, except for
- * rows on the edge of the matrix, which are left constant. */
-
- #include "dino.h"
-
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x < y ? x : y)
-
- #define M 16
- #define N 11
-
- environment node[M:id] {
-
- composite smooth (a, in iter)
-
- /* ==> Since no "in" or "out" keyword has been
- used before a, it is an in/out
- parameter. */
-
- double distributed a[M][N] map BlockRowOverlap;
-
- int iter; /* ==> Illustrates use of a non-distributed
- parameter to a composite procedure.
- Note the use of the "in" keyword in
- the parameter list. */
-
- {
- int i, j; /* Looping variables */
-
- /* Repeat the smoothing process iter times */
- for (i = 0; i < iter; i++) {
-
- /* Send out your data and receive it back again */
-
- if (i != 0) { /* ==> We don't need to communicate on the
- first iteration, because the data we
- need has been set up by the composite
- procedure call. */
-
- a[<id,id>][]# = a[<id,id>][];
-
- /* ==> Implicit send of the id'th row of a.
- Notice the use of the # sign, and how
- an assignment statement is used to
- send data. */
-
- /* ==> Used a[<id,id>][]# instead
- of a[id][]# because of a bug in DINO. */
-
- a[<max(id-1,0),min(id+1,M-1)>][]#;
-
- /* ==> Implicit receive. Receives rows id-1
- and id+1, except on the edges, where
- it only receives one row. */
-
- }
-
- /* Perform the computation, but only on non-edge nodes */
- if (id != 0 && id != M - 1)
- for (j = 0; j < N; j++)
- a[id][j] = (a[id-1][j] + a[id+1][j]) / 2;
-
- }
- }
- }
-
- environment host {
-
- void main ()
-
- {
- double a[M][N]; /* Input data */
- int iter; /* Holds the iteration count */
-
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] */
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = (i + 1)*(j + 1);
- for (i = 1; i < M - 1; i++)
- for (j = 0; j < N; j++)
- a[i][j] = 0;
-
- iter = 300; /* ==> We must use a variable to hold the
- number of iterations, because of a
- bug in DINO which doesn't allow
- passing constants to a composite
- procedure. */
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
-
- /* Perform the computation */
- smooth (a[][], iter)#;
-
- /* Printout the results */
- printf ("Result data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
- }
- }
-
-